<template>
  <!-- 选中商品 -->
  <div class="goods">
    <!-- 单个商品盒子 -->
    <div
      class="carBox"
      v-for="(item, index) in $store.state.shppingCarInfo"
      :key="item.id"
    >
      <!-- 单选框 -->
      <van-checkbox
        v-model="item.checked"
        checked-color="#ee0a24"
        @click="isChecked(index)"
      ></van-checkbox>
      <!-- 商品卡片 -->
      <van-swipe-cell class="slideBox">
        <van-card class="goods_info">
          <template #thumb>
            <div class="imgBox" @click="goDetgoods(item.productId)">
              <img :src="item.imageHost + item.mainImage" alt="" />
            </div>
          </template>
          <template #num>
            <van-stepper
              v-model="item.count"
              @plus="shopCaradd(item.productId)"
              @minus="shopCardel(item.productId)"
            />
          </template>

          <template #price>
            <p class="price">￥ {{ item.price }}</p>
          </template>

          <template #desc>
            <p class="goodsDes">{{ item.subtitle }}</p>
          </template>

          <template #title>
            <p class="goodsTitle">
              {{ item.name }}
            </p>
          </template>
        </van-card>
        <template #right>
          <van-button
            square
            text="删除"
            type="danger"
            class="delete-button cleBtn"
            @click="$parent.cleanBtn(item.id)"
          />
        </template>
      </van-swipe-cell>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      value: 1,
    };
  },
  methods: {
    // 跳转商品详情页
    goDetgoods(val) {
      this.$router.push(`/goodsEle${val}`);
    },
    // 单选框点击事件
    isChecked(val) {
      this.$store.commit("shopChecked", val);
    },
    // 步进器加号点击事件
    shopCaradd(val) {
      let temp = {
        productId: val,
        count: 1,
      };
      this.$emit("shopCarEle", temp);
    },
    // 步进器减号点击事件
    shopCardel(val) {
      let temp = {
        productId: val,
        count: -1,
      };
      this.$emit("shopCarEle", temp);
    },
  },
};
</script>

<style lang="scss" scoped>
.goods {
  .carBox {
    display: flex;
    align-items: center;
    background-color: #fff;
    margin-bottom: 11px;
    padding: 5.5px;
  }
  .slideBox {
    width: calc(100% - 20px);
  }
  .goods_info {
    text-align: left;
    background-color: #fff;

    .price {
      height: 28px;
      line-height: 28px;
      font-size: 16px;
      font-weight: 550;
      color: #ff0000;
    }

    .goodsDes {
      width: 100%;
      height: 35px;
      padding-top: 5px;
      margin-bottom: 3px;
      box-sizing: border-box;
      font-size: 13px;
      color: #ccc;
      overflow: hidden;
    }

    .goodsTitle {
      height: 36px;
      overflow: hidden;
      line-height: 18px;
    }
  }
  .cleBtn {
    height: 100%;
  }
  .imgBox {
    width: 85px;
    height: 85px;

    img {
      width: 100%;
      height: 100%;
    }
  }
}
</style>
